﻿@using Kunlun.BusinessLogic
@model IEnumerable<Kunlun.ViewModels.UserCartViewModels>
@{
    ViewBag.Title = "购物车";
}
@section Head
{
    <link href="@Url.Content("~/Content/car/Style.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/Content/base/ymPrompt.css")" type="text/css" rel="Stylesheet" />
    <script src="@Url.Content("~/Content/base/Prompt.js")" type="text/javascript"></script>
    <script language="javascript">
        $(function () {
            $(".input").live("change", function () {
                if (isNaN(this.value) || this.value > 999) {
                    Alert("请输入1-999之间的数字！");
                    return;
                }
                var dataid = $(this).attr("data");
                $.post("/MyKunlun/ModifyCarts", { "id": dataid, "number": this.value, "r": Math.random() },
				function (data) {
				    $(".money .allprice").html(data.AllPrice);
				    GetCart();
				});
            });

            $(".Delete").click(function () {
                var obj = this;
                ConfirmInfo("确定删除该订单项！", 0, 0, "", function () {
                    var dataid = $(obj).attr("data-id");
                    $.get("/MyKunlun/DeleteCarts", { "index": dataid, "r": Math.random() },
					function (data) {
					    $('#row-' + dataid).remove();
					    $('.row-' + dataid).remove();
					    $(".allprice").html(data.AllPrice)
					    GetCart();
					});
                });


            });
        });
        function GetCart() {
            $.post("/MyKunlun/GetCarts", function (data) {
                $("#mycart").html("购物车(" + data.Count + ")")
            });
        }
    </script>
}
<div class="hh">
</div>
<div class="main">
    <table class="items" cellpadding="0" cellspacing="0">
        <tr>
            <th>
                编号
            </th>
            <th>
                图片
            </th>
            <th>
                商品名称
            </th>
            <th>
                规格
            </th>
            <th>
                单价
            </th>
            <th>
                数量
            </th>
            <th>
            </th>
        </tr>
        @foreach (var item in Model.Where(o => o.Types != 0))
        {
            List<Kunlun.ViewModels.UserCartViewModels> citems = Model.Where(o => o.Index == item.Index && o.PID != item.PID).ToList();
            <tr id="row-@item.Index" class="Goods_First">
                <td rowspan='@(citems.Count + 1)' class="index">@item.Index
                </td>
                <td class="img">
                    <img alt="" src="@string.Format("{0}{1}", WebLog.ImageHttp, item.Thumnail)" onload="DrawImage(this,100,100);"/>
                </td>
                <td>
                    @item.Product - @(item.Types != 0 ? ((FrameType)item.Types).ToString() : "")
                </td>
                <td>
                    @item.Propertys
                </td>
                <td>
                    @item.Prices.ToString("C")
                </td>
                <td>
                    <input type="text" class="input" data="@item.Index"  value="@item.Numbers" />
                </td>
                <td  rowspan='@(citems.Count + 1)'>
                    <a href="javascript:var i=0;" class="Delete" data-id=@item.Index >删除</a>
                </td>
            </tr>

            foreach (Kunlun.ViewModels.UserCartViewModels citem in citems)
            {
            <tr class="row-@item.Index">
                <td class="img">
                    <img alt="" src="@string.Format("{0}{1}", WebLog.ImageHttp, citem.Thumnail)" onload="DrawImage(this,80,80);"/>
                </td>
                <td>
                    @citem.Product @(citem.Types != 0 ? "-" + ((FrameType)citem.Types).ToString() : "")
                    @(citem.Level != 0 ? "(" + ((PaperLevel)citem.Level).ToString() + ")" : "")
                </td>
                <td>
                    @citem.Propertys
                </td>
                <td>
                    @citem.Prices.ToString("C")
                </td>
                <td>
                </td>
            </tr>
            }
        }
        <tr>
            <td colspan="7" class="money">
                总金额：<span class="allprice">@string.Format("{0:F}", ViewBag.Allprice)</span>
            </td>
        </tr>
    </table>
</div>
<div class="message">
</div>
<div class="bot">
    <span><a href="@Url.Content("~/Store/Frame/Search")">继续购物</a></span>
    <span>@Html.ActionLink("清空购物车", "ClearCart")</span>
    <span>@Html.ActionLink("下一步", "Purchase")</span>
</div>
